layui.use(['form', 'layedit', 'laydate'], function(){
  var form = layui.form
  ,layer = layui.layer
  ,layedit = layui.layedit
  ,laydate = layui.laydate;
  var url = "/general/erp5/public/tripapi/travel/Save";
  var updateurl = "/general/erp5/public/tripapi/travel/Update";
  var uid = $("#hdnid").val();

  //日期
  laydate.render({
    elem: '#date'
  });
  laydate.render({
    elem: '#date1'
  });

  //自定义验证规则
  form.verify({
    title: function(value){
      if(value.length == 0){
        return '请输入项目/合同名称';
      }
    },
    content: function(value){
      layedit.sync(editIndex);
    }
  });
  
  //提交
  form.on('submit(demo1)', function(data){
    $.ajax({
      type: "POST", 
      url: url, 
      data: data.field,
      traditional: true, //是否使用传统的方式浅层序列化,若有数组参数或对象参数需要设置true!!!!!!
      dataType:"json",
      success: function(returnData){
        if(returnData.status == 200){
          layer.open({
            type: 1
            ,offset: 'auto'
            ,id: 'layerDemo'
            ,content: '<div style="padding: 20px 100px;">'+ returnData.msg +'</div>'
            ,btn: '确定'
            ,btnAlign: 'c'
            ,shade: 0
            ,yes: function(){
              layer.closeAll();
            }
          });
        }else{
          layer.open({
            type: 1
            ,offset: 'auto'
            ,id: 'layerDemo'
            ,content: '<div style="padding: 20px 100px;">'+ returnData.msg +'</div>'
            ,btn: '确定'
            ,btnAlign: 'c'
            ,shade: 0
            ,yes: function(){
              layer.closeAll();
            }
          });
        }
      }
    })
    // layer.alert(JSON.stringify(data.field), {
    //   title: '最终的提交信息'
    // })
    return false;
  });

  //提交
  form.on('submit(demo3)', function(data){
    $.ajax({
      type: "POST",
      url: updateurl+"?id="+uid,
      data: data.field,
      traditional: true, //是否使用传统的方式浅层序列化,若有数组参数或对象参数需要设置true!!!!!!
      dataType:"json",
      success: function(returnData){
        if(returnData.status == 200){
          layer.open({
            type: 1
            ,offset: 'auto'
            ,id: 'layerDemo'
            ,content: '<div style="padding: 20px 100px;">'+ returnData.msg +'</div>'
            ,btn: '确定'
            ,btnAlign: 'c'
            ,shade: 0
            ,yes: function(){
              layer.closeAll();
            }
          });
        }else{
          layer.open({
            type: 1
            ,offset: 'auto'
            ,id: 'layerDemo'
            ,content: '<div style="padding: 20px 100px;">'+ returnData.msg +'</div>'
            ,btn: '确定'
            ,btnAlign: 'c'
            ,shade: 0
            ,yes: function(){
              layer.closeAll();
            }
          });
        }
      }
    })
    // layer.alert(JSON.stringify(data.field), {
    //   title: '最终的提交信息'
    // })
    return false;
  });
  
});